Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The following C programmain(){ fork() ; fork... Start Learning for Free
The following C program
main()
{
    fork() ; fork() ; printf ("yes");
}
If we execute this core segment, how many times the string yes will be printed ?
  • a)
    Only once
  • b)
    2 times
  • c)
    4 times
  • d)
    8 times
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
The following C programmain(){ fork() ; fork() ; printf ("yes&qu...
Number of times YES printed is equal to number of process created. Total Number of Processes = 2n where n is number of fork system calls. So here n = 2, 24 = 4
fork ();   // Line 1
fork ();   // Line 2
So, there are total 4 processes (3 new child processes and one original process). Option (C) is correct.
View all questions of this test
Most Upvoted Answer
The following C programmain(){ fork() ; fork() ; printf ("yes&qu...
"Hello World\n") ; }

Explanation:

This program uses the fork() function twice, which creates two child processes. The parent process and each child process then execute the printf statement, resulting in the output of "Hello World" four times.

The execution of the program can be visualized as follows:

- The original process (parent) forks, creating a child process (child 1).
- Both the parent and child 1 processes fork again, creating two more child processes (child 2 and child 3).
- Each of the four processes executes the printf statement, resulting in the output of "Hello World" four times.

Therefore, the output of this program will be:

Hello World
Hello World
Hello World
Hello World

Note: The order in which the output is displayed may vary depending on the scheduling algorithm of the operating system.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer?
Question Description
The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer?.
Solutions for The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The following C programmain(){ fork() ; fork() ; printf ("yes");}If we execute this core segment, how many times the string yes will be printed ?a)Only onceb)2 timesc)4 timesd)8 timesCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev